<?php
// +----------------------------------------------------------------------
// | makePHP 
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://makephp.org All rights reserved.
// +----------------------------------------------------------------------
// | Licensed BSD.(http://www.make.org/BSD-license.txt)
// +----------------------------------------------------------------------
// | Author: 叁石(sanshi) <sanshi0815@tom.com>
// | Author: 白家昌<baijc2004cn@126.com>
// +----------------------------------------------------------------------
/**
 * zy_allocation_log Database of the driver class.
 *
 * @Author:    <mirze@foxmail.com>Mirze
 * @Package:   Database Operate class of the system.
 * @Copyright: Copyright (c) 2005 - 2006 
 * @Version:   $Id: DB_zy_allocation_log.class.php 2011-07-07 13:46:23 $
 * @Show Note: 设备调拨记录表
 */
/* @Package of the database class */
Class DB_zy_allocation_log extends PdoMysql
{
    /* Mysql Table Name */
    public $tableName = "zy_allocation_log";

    /**
     * Construction this Database Object.
     *
     * @Author: Mirze.
     * @Show: Get the PdoMysql Object and Set the default Charset.
     * @Return: ..
     */
    public function __construct()
    {
    		parent::__construct();
    }

    /**
     * Execute the insert method.
     *
     * @Author: Mirze.
     * @Show: Execute 'insert' method by the PdoMysql Object.
     * @Param: $values Array -- Key is the Table Coulnum and Value is that values.
     * @Return: False OR int.
     */
    public function insert_zy_allocation_log($values)
    {
        return $this->insert($this->tableName, $values);
    }

    /**
     * Execute the update method.
     *
     * @Author: Mirze.
     * @Show: Execute 'update' method by the PdoMysql Object.
     * @Param: $values Array -- Key is the Table Coulnum and Value is that values.
     * @Param: @where  Array -- Key is the Table Coulnum and Value is the where values.
     * @Return: False OR int.
     */
    public function update_zy_allocation_log($values, $where)
    {
        return $this->update($this->tableName, $values, $where);
    }
    
    /**
     * Execute the delete method.
     *
     * @Author: Mirze.
     * @Show: Execute 'delete' method by the PdoMysql Object.
     * @Param: @where  Array -- Key is the Table Coulnum and Value is the where values.
     * @Return: False OR int.
     */
    public function delete_zy_allocation_log($where)
    {
        return $this->delete($this->tableName, $where);
    }

    /**
     * Execute the select method.
     *
     * @Author: Mirze
     * @Show: Execute 'select' method by the PdoMysql Object, Return the item set.
     * @Param: $where String -- Search where.
     * @Param: $col String -- Search Order.
     * @Param: $numrows Int -- Search item num.
     * @Param: $offset Int -- Search item set offset.
     * @Param: $field String -- Search item name.
     * @Return: False OR Array.
     */
    public function getAll($where='1', $col='', $numrows=-1, $offset=-1, $field="*")
    {
        $sql = sprintf("SELECT %s FROM %s WHERE %s", $field, $this->tableName, $where);
        return $this->select($sql, $col, $numrows, $offset);
    }

    /**
     * Get one Item.
     *
     * @Author: Mirze
     * @Show: Search the database.Return one item.
     * @Param: $index Array -- Key is the index Key.Value is the index value.
     * @Return: Array.
     */
    public function getOne($allocation_log_id)
    {
        $sql = sprintf("SELECT * FROM %s WHERE allocation_log_id = '%s'", $this->tableName, $allocation_log_id);
        $result = $this->select($sql, 'allocation_log_id', 1, 0);
        return isset($result[0]) ? $result[0] : array();
    }

	/**
	 * (功能描述) 获取验证ID的记录
	 *
	 * @param 
	 * @return
	 */
	public function getRecord($allocation_id, $col='', $numrows=-1, $offset=-1, $field="*")
	{
		$where = "allocation_id = '{$allocation_id}'";
		$result = $this->getAll($where, $col, $numrows, $offset, $field);
		return (is_array($result)) ? $result : array();
	}

	/**
	 * (功能描述) 查询关联内容
	 *
	 * @param 
	 * @return
	 */
	public function getJoinRecord($allocation_id, $col='', $numrows=-1, $offset=-1, $field="*")
	{
		//$sql = sprintf("SELECT %s FROM %s WHERE allocation_id = '%s'", $field, $this->tableName, $allocation_id);
		$sql = "select zal.allocation_log_id,zal.comp_no,zal.start_time,zal.mc_state mstate,zafm.*,zml.*,zmtl.* from zy_allocation_log as zal";
		$sql .= " left join zy_auth_finish_mc as zafm on zal.comp_no=zafm.comp_no";
		$sql .= " left join zy_mc_log as zml on zafm.mc_log_id=zml.mc_log_id";
		$sql .= " left join zy_mc_transfer_log as zmtl on zmtl.comp_no=zal.comp_no";
		$sql .= " where zal.allocation_id={$allocation_id}";
		$cn_name = !empty($_GET['cn_name']) ? trim($_GET['cn_name']) : '';
		if($cn_name){
			$sql .= " and zml.mc_cn_name like '%{$cn_name}%'";
		}
        $result = $this->select($sql, $col, $numrows, $offset);
		return (is_array($result)) ? $result : array();
	}
    
}

/* Public function is the Class method, Design by Hooker framework designer */
/* CreateTime: 2011-07-07 13:46:23 */

?>